﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WeakScript
{
    static class Operations
    {

        public static void Sum(WeakVar a, WeakVar b, WeakVar res)
        {
            res.InnerType = a.InnerType;

            if (res.InnerType == WeakVar.InternalType.FLT) res.floatValue = a.floatValue + b.floatValue;
            else if (a.InnerType == WeakVar.InternalType.STR) res.stringValue = a.stringValue + b.stringValue;
            else throw new Exception("Unsupported operation for " + a + " and " + b); 
        }

        public static void Sub(WeakVar a, WeakVar b, WeakVar res)
        {           
            res.InnerType = a.InnerType;

            if (res.InnerType == WeakVar.InternalType.FLT) res.floatValue = a.floatValue - b.floatValue;
            else throw new Exception("Unsupported operation for " + a + " and " + b); 
        }

        public static void Mul(WeakVar a, WeakVar b, WeakVar res)
        {
            res.InnerType = a.InnerType;

            if (res.InnerType == WeakVar.InternalType.FLT) res.floatValue = a.floatValue * b.floatValue;
            else throw new Exception("Unsupported operation for " + a + " and " + b); 
        }

        public static void Div(WeakVar a, WeakVar b, WeakVar res)
        {           
            res.InnerType = a.InnerType;

            if (res.InnerType == WeakVar.InternalType.FLT) res.floatValue = a.floatValue / b.floatValue;
            else throw new Exception("Unsupported operation for " + a + " and " + b); 
        }        

    }
}
